﻿using Entity.BaseInfo.DTO.Staff;
using Entity.BaseInfo.View.Staff;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 员工表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class StaffController : ControllerBase
    {
        /**
         * 员工业务接口
         */
        private readonly StaffService _staffService;

        /**
         * 构造函数注入
         */
        public StaffController(StaffService staffService)
        {
            _staffService = staffService;
        }

        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="staffSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(StaffView), 200)]
        public async Task<IActionResult> GetStaffList([FromQuery] StaffSearchDTO staffSearchDTO)
        {
            var response = await _staffService.GetStaffList(staffSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增员工
        /// </summary>
        /// <param name="staffAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddStaff([FromBody] StaffAddDTO staffAddDTO)
        {
            var response = await _staffService.AddStaff(staffAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新员工
        /// </summary>
        /// <param name="staffUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutStaff([FromBody] StaffUpdateDTO staffUpdateDTO)
        {
            var response = await _staffService.PutStaff(staffUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除员工
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteStaff([FromQuery] string Id)
        {
            var response = await _staffService.DeleteStaff(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除员工 - 批量
        /// </summary>
        [HttpPost("Multi")]
        public async Task<IActionResult> DeleteStaffMulti([FromBody] List<string> Ids)
        {
            var response = await _staffService.DeleteStaffMulti(Ids);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 启用员工 - 批量
        /// </summary>
        [HttpPost("Enable")]
        public async Task<IActionResult> EnableStaff([FromBody] List<string> Ids)
        {
            var response = await _staffService.EnableStaff(Ids);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 禁用员工 - 批量
        /// </summary>
        [HttpPost("Disable")]
        public async Task<IActionResult> DisableStaff([FromBody] List<string> Ids)
        {
            var response = await _staffService.DisableStaff(Ids);
            return StatusCode(response.Status, response);
        }
    }
}
